var ScrollText = function () {
  var template = /* html */ `
    <el-collapse-transition>
      <div class="scroll-text" :key="getKey()">
        <slot :text="showText" v-if="showText!==null">
          {{showText}}
        </slot>
      </div>
    </el-collapse-transition>
  `;

  return {
    props: {
      textList: {
        type: Array,
        required: true
      }
    },

    watch: {
      textList: function () {
        this.currentIndex = 0;
        this.scrollRuning(true);
      }
    },

    computed: {
      totalCount: function () {
        var textList = this.textList;
        if (SysUtil.isEmpty(textList)) {
          return 0;
        }
        return textList.length;
      },

      showText: function () {
        var textList = this.textList;
        if (SysUtil.isEmpty(textList)) {
          return null;
        }
        var currentIndex = this.currentIndex;
        var textObj = textList[currentIndex];
        if (textObj === undefined) {
          textObj = textList[textList.length - 1];
        }
        return textObj;
      }
    },

    data: function () {
      return {
        currentIndex: 0,
        timeout: null
      };
    },

    created: function () {
      this.scrollRuning(true);
    },

    destroyed: function () {
      var timeout = this.timeout;
      if (timeout !== null) {
        clearTimeout(timeout);
      }
    },

    methods: {
      scrollRuning: function (isInit) {
        var timeout = this.timeout;
        if (timeout !== null) {
          clearTimeout(timeout);
        }

        if (isInit) {
          var textList = this.textList;
          if (SysUtil.isEmpty(textList) || textList.length <= 1) {
            return;
          }
        }

        var self = this;
        this.timeout = setTimeout(function () {
          self.timeout = null;
          var currentIndex = (self.currentIndex + 1) % self.totalCount;
          self.currentIndex = currentIndex;
          self.scrollRuning();
        }, 5000);
      },
      getKey: function () {
        return SysUtil.getId();
      }
    },

    template: template
  };
}();